# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane


#fastlane 版本号
fastlane_version "2.199.0"
#定义打包平台
default_platform :iOS
currentTime = Time.new.strftime("%Y%m%d%s")
#指定项目的scheme的名称
scheme = "HLTestDemo"
#蒲公英api_key和user_key
api_key="dd78b963d87ce03001c5f687e019b9b0"
user_key="c58c79021200ef0d7e1eec6b8a7421be"
configuration="Debug"
method="development"
number="0"

default_platform(:ios)

platform :ios do
  desc "测试fastlane自动打包上传"
  before_all do |lane, options|
    puts("*************| options #{options} |*************")

    #options参数
    configuration  = options[:configuration] ||  "Debug"
    method = options[:method] || 'development'

     # 版本号更新
     update_version(options)

  end

  def update_version(options)
    puts("*************| 更新version #{options[:version]} |*************")
    puts("*************| 更新build   #{options[:build]}   |*************")
    increment_version_number(
        version_number: options[:version]
    )

    increment_build_number(
        build_number: options[:build]
    )
  end

  lane:archive do #打包方法
  gym(
      scheme:"HLTestDemo", #项目名称
      output_directory: "/Users/hulinhu/Desktop", # 打包后的 ipa 文件存放的目录
      configuration:"#{configuration}",
      output_name: "#{scheme}_#{configuration}_#{currentTime}",  # ipa文件名
      # 指定打包所使用的输出方式：app-store、ad-hoc、enterprise、development
      export_method:"#{method}",
      # 自动管理证书的时候，Xcode 9及以上没有权限获取钥匙串里面的证书，必须加上这个才能打包成功
      export_xcargs: "-allowProvisioningUpdates"

    )
  # puts "开始上传蒲公英"
  # # pgyer(api_key: "#{api_key}", user_key: "#{user_key}")
  end
end
